package com.example.mapper;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.pojo.SysRole;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.vo.RoleVo;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 角色表 Mapper 接口
 * </p>
 *
 * @author lyj
 * @since 2023-02-16
 */
public interface SysRoleMapper extends BaseMapper<SysRole> {

    @Select("select sr.* \n" +
            "from sys_role sr,\n" +
            "sys_user_role sur,\n" +
            "sys_user su\n" +
            "where sr.id=sur.role_id\n" +
            "and sur.user_id=su.id\n" +
            "and sur.del_flag=0\n" +
            "and sr.del_flag=0\n" +
            "and su.id=#{userId}")
    List<SysRole> queryByUserId(Long userId);

    @Select("select so.name officeName, sr.*, sd.label dataScopeName\n" +
            "from sys_role sr \n" +
            "left join sys_office so on sr.office_id=so.id " +
            "left join sys_dict sd on sr.data_scope=sd.value and sd.type='sys_data_scope' ${ew.customSqlSegment}")
    Page<RoleVo> queryByCondition(Page<RoleVo> page, QueryWrapper<RoleVo> ew);
}
